package display.screens {
	
	import display.screens.about.AboutScreenContent;
	import display.scrollableWindow.ScrollableWindow;
	import display.showcase.Showcase;
	import display.showcase.ShowcaseItem;
	
	import events.LoadingEvent;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import org.ilovecode.display.Gallery;
	import org.ilovecode.mvc.View;
	import org.ilovecode.screen.Screen;
	import org.ilovecode.screen.ScreenName;
	
	/**
	 * Screen displays information about project.
	 * 
	 * @author Vjekoslav Ratkajec
	 */
	public class AboutScreen extends Screen {
		
		//{ region Stage elements
		
		//Content which will be loaded in scrollable window
		private var content:AboutScreenContent;
		//Window to display content
		public var contentWindow:ScrollableWindow;
		
		//} endregion
		
		//private var showcase:Showcase = new Showcase();
		private var gallery:Gallery;
		
		/**
		 * Create new instance of About screen.
		 */
		public function AboutScreen() {
			super(ScreenName.ABOUT, "aboutScreen");
			
			//Setup content in window
			/*contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
			
			init();*/
			
			//(this.stage != null) ? construct() : this.addEventListener(Event.ADDED_TO_STAGE, construct);
		}
		
		/*private function construct(event:Event=null):void
		{
			if (this.hasEventListener(Event.ADDED_TO_STAGE)) this.removeEventListener(Event.ADDED_TO_STAGE, construct);
			
			contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
			
			init();
		}
		
		private function init():void {
			contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
			
			gallery = new Gallery(900, 530, "none", false);
			gallery.path = "images/about/items.xml";
			gallery.thumbnailsContainerWidth = 124;
			gallery.thumbnailsContainerHeight = 281;
			gallery.addEventListener(LoadingEvent.SHOW, gallery_Show);
			gallery.addEventListener(LoadingEvent.HIDE, gallery_Hide);
			this.addChild(gallery);
		}
		
		private function gallery_Show(event:LoadingEvent):void {
			this.dispatchEvent(event.clone());
		}
		
		private function gallery_Hide(event:LoadingEvent):void {
			this.dispatchEvent(event.clone());
		}*/
		
		override protected function construct():void
		{
			super.construct();
			
			gallery = new Gallery(900, 530, "none", false);
			content = new AboutScreenContent();
		}
		
		override protected function initUI():void
		{
			super.initUI();
			
			contentWindow.configUI(900, 180);
			contentWindow.setContent(content);
			
			var xml:XML = controller.getScreenXML("about");
			gallery.path = String(xml.gallery.@url);
			//gallery.path = "images/about/items.xml";
			gallery.thumbnailsContainerWidth = 124;
			gallery.thumbnailsContainerHeight = 281;
			this.addChild(gallery);
		}
		
		override protected function addListeners():void
		{
			super.addListeners();
			gallery.addEventListener(LoadingEvent.SHOW_PROGRESS_ICON, update);
			gallery.addEventListener(LoadingEvent.HIDE_PROGRESS_ICON, update);
		}
		
		override protected function removeListeners():void
		{
			super.removeListeners();
			gallery.removeEventListener(LoadingEvent.SHOW_PROGRESS_ICON, update);
			gallery.removeEventListener(LoadingEvent.HIDE_PROGRESS_ICON, update);
		}
		
		override protected function update(event:Event):void
		{
			switch(event.type)
			{
				case LoadingEvent.SHOW_PROGRESS_ICON:
					//Fallthrough
				case LoadingEvent.HIDE_PROGRESS_ICON:
					this.dispatchEvent(event.clone());
					break;
				default:
					super.update(event);
					break;
			}
		}
	}

}